
/* 
 * This file is part of FreeBMS - an open source battery management system
 *
 * DTC Headers
 * 
 * NOTE: This code is designed to be compiled using SOURCEBOOST (http://www.sourceboost.com)
 */
 
/* This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */ 
#ifndef _DTC_H_
#define _DTC_H_

#include "types.h"

// Global defines
#define DTC_PRIORITY_LOW	0		// Low priority DTC (Relays on, buzzer off)
#define DTC_PRIORITY_MED	1		// Medium priority DTC (Relays off, buzzer off)
#define DTC_PRIORITY_HI		2		// High priority DTC (Relays off, buzzer on)

// Message record data structure
struct dtc_data {
	struct dtc_data *next; 		// Next DTC in list
	BYTE length;				// Length of message
	BYTE data[8];				// Message buffer: [id] [priority] [data1...data6]
};

// External variables
extern struct dtc_data *first_dtc;	// First DTC pointer
extern bool error_memfault;			// Memory found inconsistent with polled data
extern bool error_trisfault;		// Tris registers have been overridden
extern bool error_sensorfault;		// No current sensor detected (or bogus values)
extern bool error_relayfault;		// Relays are not cutting off current flow
extern bool error_canerrors;		// Too many CANBUS errors have occurred
extern bool error_critical;			// Critical error has occurred

// Function prototypes
void init_dtc();
struct dtc_data *find_dtc(BYTE id);
struct dtc_data *update_dtc(BYTE length, BYTE *buffer);
struct dtc_data *insert_dtc(BYTE length, BYTE *buffer, BYTE save);
void load_dtcs(BYTE highonly);
void save_dtcs();
void clear_dtcs();

#endif // _DTC_H_
